<template>
    <div>
        <h1>用药修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th align="right">药品名称<span style="color: red;">*</span></th>
                    <th><input type="text" v-model="queryinfo.UName"></th>
                </tr>
                <tr>
                    <th align="right">科室名称</th>
                    <th>
                        <select v-model="queryinfo.UDName">
                            <option value="">请选择</option>
                            <option :value="item.DName" v-for="item in list">{{ item.DName }}</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <th align="right">用药日期<span style="color: red;">*</span></th>
                    <th><input type="date" v-model="queryinfo.UDate"></th>
                </tr>
                <tr>
                    <th align="right">病人姓名<span style="color: red;">*</span></th>
                    <th><input type="text" v-model="queryinfo.UPerson"></th>
                </tr>
                <tr>
                    <th align="right">病房号码<span style="color: red;">*</span></th>
                    <th><input type="text" v-model="queryinfo.UNum"></th>
                </tr>
                <tr>
                    <th align="right">用药状态</th>
                    <th>
                        <input type="radio" name="state" v-model="queryinfo.UState" value="1">已完成
                        <input type="radio" name="state" v-model="queryinfo.UState" value="0">未开始
                    </th>
                </tr>
                <tr>
                    <th align="right">配药医生<span style="color: red;">*</span></th>
                    <th><input type="text" v-model="queryinfo.UDoctor"></th>
                </tr>
                <tr>
                    <th align="right"></th>
                    <th><input type="button" value="修改" class="btn btn-primary" @click="ok"></th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
const route = useRoute()
const router = useRouter()


let queryinfo:any=reactive({
    "UId": "",
  "UName": "",
  "UDName": "",
  "UDate": "",
  "UPerson": "",
  "UNum": "",
  "UState": 0,
  "UDoctor": "",
})


let list:any = ref([])

onMounted(()=>{
    getdata() 
    getlist()
})


const getlist=()=>{
    axios({
        url:'/api/Use/GetUseModel',
        method:'get',
        params:{
            UId:route.query.UId
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(queryinfo,res.data)
        queryinfo.UDate=res.data.UDate.substring(0,10)
    })
}


const getdata=()=>{
    axios({
        url:'/api/Depart/GetDepartment',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        list.value=res.data
    })
}

const ok=()=>{
    if(queryinfo.UName==""){
        alert("药品名称不得为空")
        return
    }
    if(queryinfo.UDate==""){
        alert("用药日期不得为空")
        return
    }
    if(queryinfo.UPerson==""){
        alert("病人姓名不得为空")
        return
    }
    if(queryinfo.UNum==""){
        alert("病房号码不得为空")
        return
    }
    if(queryinfo.UDoctor==""){
        alert("配药医生不得为空")
        return
    }
    axios({
        url:'/api/Use/UpdateUse',
        method:'put',
        data:queryinfo
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("修改成功")
            router.push("/uselist")
        }
        else{
            alert("修改失败")
            return
        }
    })
}

</script>

<style scoped>

</style>